package com.ehsy.statement;

import com.ehsy.common.ResponseVo;
import com.ehsy.model.UserInfo;
import com.ehsy.service.RequestBodyService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YanZhen_Li
 * @version 1.0
 * @title A5请求体设置
 * @description
 * @create 2024/6/17 17:25
 */
@SpringBootTest
public class A5请求体设置 {
    @Resource
    RequestBodyService service;

    /**
     * 常规请求体请求
     */
    @Test
    public void test001() {
        ResponseVo<Map<String, Object>> test01 = service.test01("张三丰", "石根高卧忘其年，三光沉沦性自圆，气气归玄窍，息息任天然。");
        ResponseVo<Map<String, Object>> test02 = service.test02("火云邪神", 18, 99999999L);
        ResponseVo<UserInfo> test03 = service.test03(new UserInfo("五娃", "18", "男", "北京", "12345678910", "123@qq.com", "123456"));
        ResponseVo<UserInfo> test04 = service.test04(new UserInfo("薛仁贵", "18", "男", "北京", "12345678910", "123@qq.com", "123456"));
        ResponseVo<UserInfo> test05 = service.test05("狗剩", "123456");
        ResponseVo<UserInfo> test06 = service.test06(new HashMap<String, Object>(){{
            put("name", "刘德华");
            put("password", "123456");
            put("age", "18");
        }});
        ResponseVo<List<String>> test07 = service.test07(Arrays.asList("李白", "望穿秋水", "张学友", "成龙"));
        ResponseVo<UserInfo> test08 = service.test08(new UserInfo("刘德华", "18", "男", "北京", "12345678910", "123@qq.com", "123456"));

        System.out.println(test01);
        System.out.println(test02);
        System.out.println(test03);
        System.out.println(test04);
        System.out.println(test05);
        System.out.println(test06);
        System.out.println(test07);
        System.out.println(test08);
    }

    /**
     * xml请求体请求
     */
    @Test
    public void test002() {
        String test09 = service.test09(new UserInfo("罩不住", "18", "男", "北京", "12345678910", "123@qq.com", "123456"));
        System.out.println(test09);
    }

    /**
     * 二进制传输
     */
    @Test
    public void test003() throws IOException {
        byte[] bytes = "我是一个文件".getBytes();
        String test10 = service.test10(bytes, "test.txt");
        File file = new File("pom.xml");
        String test11 = service.test11(file, "test.txt");
        String test12 = service.test12(Files.newInputStream(file.toPath()), "test.txt");

        System.out.println(test10);
        System.out.println(test11);
        System.out.println(test12);
    }
}
